package com.study.demo.controller;

import com.study.demo.common.Result;
import com.study.demo.entity.User;
import com.study.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yinyin
 * @create 2024/12/19 下午 5:17
 */
@Api("测试")
@RestController
public class FirstController {

    @Autowired
    private UserService userService;

    @ApiOperation("获取id")
    @GetMapping("user")
    public void  testGet(Integer id){
        System.out.println("获取到的id为"+id);
    }
    @ApiOperation("path获取id")
    @GetMapping("path/{id}")
    public void testPath(@PathVariable Integer id){
        System.out.println("获取到的id为"+id);
    }

    @ApiOperation("登录")
    @PostMapping("login")
    public void testForm(@RequestBody User user){
        System.out.println("username="+user.getUsername());
        System.out.println("password="+user.getPassword());
    }

    @ApiOperation("获取用户列表")
    @GetMapping("getUsers")
    public Result getAll(){
        List<User> list = userService.getAllUser();
        return Result.ok().data("users",list);
    }
}
